{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Uncommon Words from Two Sentences"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #hash-table #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #哈希表 #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: uncommonFromSentences"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #两句话中的不常见单词"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p><strong>句子</strong> 是一串由空格分隔的单词。每个 <strong>单词</strong><em> </em>仅由小写字母组成。</p>\n",
    "\n",
    "<p>如果某个单词在其中一个句子中恰好出现一次，在另一个句子中却 <strong>没有出现</strong> ，那么这个单词就是 <strong>不常见的</strong><em> </em>。</p>\n",
    "\n",
    "<p>给你两个 <strong>句子</strong> <code>s1</code> 和 <code>s2</code> ，返回所有 <strong>不常用单词</strong> 的列表。返回列表中单词可以按 <strong>任意顺序</strong> 组织。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<ol>\n",
    "</ol>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s1 = \"this apple is sweet\", s2 = \"this apple is sour\"\n",
    "<strong>输出：</strong>[\"sweet\",\"sour\"]\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s1 = \"apple apple\", s2 = \"banana\"\n",
    "<strong>输出：</strong>[\"banana\"]\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= s1.length, s2.length &lt;= 200</code></li>\n",
    "\t<li><code>s1</code> 和 <code>s2</code> 由小写英文字母和空格组成</li>\n",
    "\t<li><code>s1</code> 和 <code>s2</code> 都不含前导或尾随空格</li>\n",
    "\t<li><code>s1</code> 和 <code>s2</code> 中的所有单词间均由单个空格分隔</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [uncommon-words-from-two-sentences](https://leetcode.cn/problems/uncommon-words-from-two-sentences/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [uncommon-words-from-two-sentences](https://leetcode.cn/problems/uncommon-words-from-two-sentences/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"this apple is sweet\"\\n\"this apple is sour\"', '\"apple apple\"\\n\"banana\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "\n",
    "        freq = Counter(s1.split()) + Counter(s2.split())\n",
    "        ans = list()\n",
    "        for word, occ in freq.items():\n",
    "            if occ == 1:\n",
    "                ans.append(word)\n",
    "        return ans\n",
    "\n",
    "\n",
    "        # ls1 = s1.split()\n",
    "        # ls2 = s2.split()\n",
    "\n",
    "        # c1 = Counter(ls1) - Counter(ls2)\n",
    "        # c2 = Counter(ls2) - Counter(ls1)\n",
    "\n",
    "        # res = []\n",
    "        # for key in c1:\n",
    "        #     if Counter(ls1)[key] == 1:\n",
    "        #         res.append(key)\n",
    "        # for key in c2:\n",
    "        #     if Counter(ls2)[key] == 1:\n",
    "        #         res.append(key)\n",
    "\n",
    "        # return res\n",
    "\n",
    "        #不使用Counter的解决方案\n",
    "        # ls1 = s1.split()\n",
    "        # ls2 = s2.split()\n",
    "\n",
    "        # res = []\n",
    "        # lsmap1 = {}\n",
    "        # for word in ls1:\n",
    "        #     if word not in lsmap1:\n",
    "        #         lsmap1[word] = 1\n",
    "        #     else:\n",
    "        #         lsmap1[word] += 1\n",
    "        \n",
    "        # for word in ls2:\n",
    "        #     if word not in lsmap1:\n",
    "        #         lsmap1[word] = 1\n",
    "        #     else:\n",
    "        #         lsmap1[word] += 1\n",
    "\n",
    "        # for key in lsmap1:\n",
    "        #     if lsmap1[key] == 1:\n",
    "        #         res.append(key)\n",
    "\n",
    "        # return res\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        hax = {}\n",
    "        s = s1 + ' ' + s2\n",
    "        for x in s.split():\n",
    "            if x not in hax:\n",
    "                hax[x] = 1\n",
    "            else:\n",
    "                hax[x] += 1\n",
    "\n",
    "        return [x for x in hax if hax[x] == 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        a = Counter(s1.split())\n",
    "        b = Counter(s2.split())\n",
    "        a.update(b)\n",
    "        return [x for x in a if a[x] == 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        def split_string(s):\n",
    "            i = 0\n",
    "            count = 0\n",
    "            s_list = []\n",
    "            while i < len(s):\n",
    "                if s[i] == \" \":\n",
    "                    s_list.append(s[i-count:i])\n",
    "                    count = 0\n",
    "                else:\n",
    "                    count = count + 1\n",
    "                i = i + 1\n",
    "            s_list.append(s[i-count:i])\n",
    "            return s_list\n",
    "        s1_list = split_string(s1)\n",
    "        s2_list = split_string(s2)\n",
    "        s1_dic = {}\n",
    "        s2_dic = {}\n",
    "        ans = []\n",
    "        s2_set = set(s2_list)\n",
    "        s1_set = set(s1_list)\n",
    "        for word in s1_list:\n",
    "            if word not in s1_dic:\n",
    "                s1_dic[word] = 1\n",
    "            else:\n",
    "                s1_dic[word] += 1\n",
    "        for key in s1_dic:\n",
    "            if s1_dic[key] == 1 and key not in s2_set:\n",
    "                ans.append(key)\n",
    "\n",
    "        for word in s2_list:\n",
    "            if word not in s2_dic:\n",
    "                s2_dic[word] = 1\n",
    "            else:\n",
    "                s2_dic[word] += 1\n",
    "        for key in s2_list:\n",
    "            if s2_dic[key] == 1 and key not in s1_set:\n",
    "                ans.append(key)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        hax = defaultdict(int)\n",
    "        s = s1 + ' ' + s2\n",
    "        for x in s.split():\n",
    "            hax[x] += 1\n",
    "\n",
    "        return [x for x in hax if hax[x] == 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        a = Counter(s1.split(' '))\n",
    "        b = Counter(s2.split(' '))\n",
    "        return [i for i,v in a.items() if v==1 and i not in b ]+[i for i,v in b.items() if v==1 and i not in a]\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        l1 = s1.split(' ')\n",
    "        l2 = s2.split(' ')\n",
    "        ans = []\n",
    "        for s in l1:\n",
    "            if s not in l2 and l1.count(s) == 1:\n",
    "                ans.append(s)\n",
    "        for s in l2:\n",
    "            if s not in l1 and l2.count(s) == 1:\n",
    "                ans.append(s)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        a=[]\n",
    "        m=Counter((s1+' '+s2).split())\n",
    "        for i in m:\n",
    "            if m[i]==1:\n",
    "                a.append(i)\n",
    "        return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        a=[]\n",
    "        m=Counter(s1.split())\n",
    "        n=Counter(s2.split())\n",
    "        for i in m:\n",
    "            if m[i]==1 and i not in n:\n",
    "                a.append(i)\n",
    "        for i in n:\n",
    "            if n[i]==1 and i not in m:\n",
    "                a.append(i)\n",
    "        return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        words=Counter(s1.split())+Counter(s2.split())\n",
    "\n",
    "        onetime=list()\n",
    "        for k,v in words.items():\n",
    "            if v==1:\n",
    "               onetime.append(k)\n",
    "        return onetime\n",
    "\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        dic1={}\n",
    "        dic2={}\n",
    "        li=[]\n",
    "        s1=s1.split()\n",
    "        s2=s2.split()\n",
    "        for i in s1:\n",
    "            dic1[i]=dic1.get(i,0)+1\n",
    "        for i in s2:\n",
    "            dic2[i]=dic2.get(i,0)+1\n",
    "        for i in dic1:\n",
    "            if dic1[i]==1 and i not in s2:\n",
    "                li.append(i)\n",
    "        for i in dic2:\n",
    "            if dic2[i]==1 and i not in s1:\n",
    "                li.append(i)\n",
    "        return li\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        c1, c2 = Counter(s1.split()), Counter(s2.split())\n",
    "        return [\n",
    "            w\n",
    "            for w, f in c1.items()\n",
    "            if f == 1 and w not in c2\n",
    "        ] + [\n",
    "            w\n",
    "            for w, f in c2.items()\n",
    "            if f == 1 and w not in c1\n",
    "        ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        a = Counter(s1.split())\n",
    "        b = Counter(s2.split())\n",
    "        a.update(b)\n",
    "        return [x for x in a if a[x] == 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        a1, a2 = s1.split(' '), s2.split(' ')\n",
    "        cnt1, cnt2 = Counter(a1), Counter(a2)\n",
    "        return [s for s in a1 if s not in a2 and cnt1[s] == 1] + [s for s in a2 if s not in a1 and cnt2[s] == 1]\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        s=s1.split(\" \")\n",
    "        t=s2.split(\" \")\n",
    "        m=[i.strip() for i in s]\n",
    "        n=[i.strip() for i in t]\n",
    "        c1=Counter(m)\n",
    "        c2=Counter(n)\n",
    "        res=[]\n",
    "        for i in c1:\n",
    "            if  c1[i]==1 and i not in c2:\n",
    "                res.append(i)\n",
    "        for i in c2:\n",
    "            if  c2[i]==1 and i not in c1:\n",
    "                res.append(i)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        hax = {}\n",
    "        s = s1 + ' ' + s2\n",
    "        for x in s.split():\n",
    "            if x not in hax:\n",
    "                hax[x] = 1\n",
    "            else:\n",
    "                hax[x] += 1\n",
    "\n",
    "        return [x for x in hax if hax[x] == 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1, s2):\n",
    "        wordList = []\n",
    "        list1 = s1.split()\n",
    "        list2 = s2.split()\n",
    "        words = {}\n",
    "        for word in list1:\n",
    "            if word not in words:\n",
    "                words[word] = 1\n",
    "            else:\n",
    "                words[word] += 1\n",
    "        for word in list2:\n",
    "            if word not in words:\n",
    "                words[word] = 1\n",
    "            else:\n",
    "                words[word] += 1\n",
    "        for word in words:\n",
    "            if words[word] == 1:\n",
    "                wordList.append(word)\n",
    "        return wordList\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        List_s1 = s1.split(' ')\n",
    "        List_s2 = s2.split(' ')\n",
    "        List_s3 = [i for i in set(List_s1) if (List_s1.count(i) == 1 and i not in List_s2)]\n",
    "        List_s4 = [i for i in set(List_s2) if (List_s2.count(i) == 1 and i not in List_s1)]\n",
    "        List_s3.extend(List_s4)\n",
    "        return List_s3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        tuple1 = {}\n",
    "        str1 = s1.split(' ')\n",
    "        str2 = s2.split(' ')\n",
    "        for i in str1:\n",
    "            if tuple1.get(i) == None:\n",
    "                tuple1[i] = 1\n",
    "            else:\n",
    "                tuple1[i] +=1\n",
    "\n",
    "        for i in str2:\n",
    "            if tuple1.get(i) == None:\n",
    "                tuple1[i] = 1\n",
    "            else:\n",
    "                tuple1[i] += 1\n",
    "\n",
    "        list1 = [key for key, value in tuple1.items() if value == 1]\n",
    "        return list1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        lst = s1.split(' ') + s2.split(' ')\n",
    "        s_dict = {}\n",
    "        for s in lst:\n",
    "            if s_dict.get(s):\n",
    "                s_dict[s] += 1\n",
    "            else:\n",
    "                s_dict[s] = 1\n",
    "        rtn_lst = []\n",
    "        for s, num in s_dict.items():\n",
    "            if num == 1:\n",
    "                rtn_lst.append(s)\n",
    "        return rtn_lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        # A并B - A 交 B\n",
    "        # l1 = s1.split(' ')\n",
    "        # l2 = s2.split(' ')\n",
    "        \n",
    "        # set1 = set(s1.split(' ')) | set(s2.split(' '))\n",
    "        # set2 = set(s1.split(' ')) & set(s2.split(' '))\n",
    "        #return list(set1 - set2)\n",
    "        d = Counter(s1.split()) + Counter(s2.split())\n",
    "        return [w for w in d if d[w] == 1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        # a=s1.split(' ')\n",
    "        # b=s2.split(' ')\n",
    "        # d=list(set(a))\n",
    "        # e=list(set(b))\n",
    "        # c=f=[]\n",
    "        # for i in d:\n",
    "        #     if (i not in e) and a.count(i)==1:\n",
    "        #         c.append(i)\n",
    "        #     elif i in e:\n",
    "        #         e.remove(i)\n",
    "        # for j in e:\n",
    "        #     if b.count(j)==1:\n",
    "        #         f.append(j)\n",
    "        # return c+f\n",
    "   \n",
    "        freq = Counter(s1.split()) + Counter(s2.split())\n",
    "        \n",
    "        ans = list()\n",
    "        for word, occ in freq.items():\n",
    "            if occ == 1:\n",
    "                ans.append(word)\n",
    "        \n",
    "        return ans\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        counter = Counter(s1.split(\" \")) + Counter(s2.split(\" \"))\n",
    "        return [key for key, value in counter.items() if value == 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        words_1 = s1.split(' ')\n",
    "        words_2 = s2.split(' ')\n",
    "        merge = words_1 + words_2\n",
    "        words = {}\n",
    "        for word in merge:\n",
    "            words[word] = words.get(word,0) + 1\n",
    "        res = []\n",
    "        for key, value in words.items():\n",
    "            if value == 1:\n",
    "                res.append(key)\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        # ls1 = s1.split()\n",
    "        # ls2 = s2.split()\n",
    "\n",
    "        # c1 = Counter(ls1) - Counter(ls2)\n",
    "        # c2 = Counter(ls2) - Counter(ls1)\n",
    "\n",
    "        # res = []\n",
    "        # for key in c1:\n",
    "        #     if Counter(ls1)[key] == 1:\n",
    "        #         res.append(key)\n",
    "        # for key in c2:\n",
    "        #     if Counter(ls2)[key] == 1:\n",
    "        #         res.append(key)\n",
    "\n",
    "        # return res\n",
    "\n",
    "        #不使用Counter的解决方案\n",
    "        ls1 = s1.split()\n",
    "        ls2 = s2.split()\n",
    "\n",
    "        res = []\n",
    "        lsmap1 = {}\n",
    "        for word in ls1:\n",
    "            if word not in lsmap1:\n",
    "                lsmap1[word] = 1\n",
    "            else:\n",
    "                lsmap1[word] += 1\n",
    "        \n",
    "        for word in ls2:\n",
    "            if word not in lsmap1:\n",
    "                lsmap1[word] = 1\n",
    "            else:\n",
    "                lsmap1[word] += 1\n",
    "\n",
    "        for key in lsmap1:\n",
    "            if lsmap1[key] == 1:\n",
    "                res.append(key)\n",
    "\n",
    "        return res\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        sL1, sL2 = s1.split(), s2.split()\n",
    "        res = []\n",
    "        for s in set(sL1) ^ set(sL2):\n",
    "            if sL1.count(s) == 1 or sL2.count(s) == 1:\n",
    "                res.append(s)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> list[str]:\n",
    "        s = s1 + ' ' + s2\n",
    "        res = []\n",
    "        counts = collections.Counter(s.split())\n",
    "        for k, v in counts.items():\n",
    "            if v == 1:\n",
    "                res.append(k)\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        from collections import Counter\n",
    "        s3=s1+' '+s2\n",
    "        list_=s3.split(' ')\n",
    "        zd=Counter(list_)\n",
    "        buchangjian=[]\n",
    "        for key,value in zd.items():\n",
    "            if value==1:\n",
    "                buchangjian.append(key)\n",
    "        return buchangjian"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        ds1,ds2 = Counter(s1.split(' ')),Counter(s2.split(' '))\n",
    "        ds3 = ds1 + ds2\n",
    "        return [x for x,v in ds3.items() if v == 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        d = Counter(s1.split()) + Counter(s2.split())\n",
    "        return [w for w in d if d[w] == 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        list = s1.split() + s2.split()\n",
    "        return ([item for item in list if list.count(item) == 1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        from collections import Counter\n",
    "        s3=s1+' '+s2\n",
    "        list_=s3.split(' ')\n",
    "        zd=Counter(list_)\n",
    "        buchangjian=[]\n",
    "        for key,value in zd.items():\n",
    "            if value==1:\n",
    "                buchangjian.append(key)\n",
    "        return buchangjian"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) :\n",
    "        l1 = s1.split()\n",
    "        l2 = s2.split()\n",
    "        d = Counter(l1) + Counter(l2)\n",
    "        return [x  for x in d if d[x]==1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        res = []\n",
    "        \n",
    "        s = (s1+' '+s2).split()\n",
    "        for i in set(s):\n",
    "            if s.count(i) == 1:\n",
    "                res.append(i)\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        l1=[]\n",
    "        l2=[]\n",
    "        def word(s,l):\n",
    "            ans=str()\n",
    "            for i in s:\n",
    "                if i!=' ':\n",
    "                    ans+=i\n",
    "                else:\n",
    "                   l.append(ans)\n",
    "                   ans=str()\n",
    "            l.append(ans)\n",
    "        word(s1,l1)\n",
    "        word(s2,l2)\n",
    "        aaa=[]\n",
    "        def check(a):\n",
    "            if (a in l1 and a not in l2 and l1.count(a)==1) or(a in l2 and a not in l1 and l2.count(a)==1):\n",
    "                aaa.append(a)\n",
    "        for i in l1+l2:\n",
    "            check(i)\n",
    "        return aaa\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        s = s1.split() + s2.split()\n",
    "        return [x for x in s if s.count(x) == 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        freq = Counter(s1.split()) + Counter(s2.split())\n",
    "\n",
    "        ans = list()\n",
    "        for word, occ in freq.items():\n",
    "            if occ == 1:\n",
    "                ans.append(word)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        s1_list, s2_list = s1.split(\" \"), s2.split(\" \")\n",
    "        s1_freq, s2_freq = collections.Counter(s1_list), collections.Counter(s2_list)\n",
    "        s1_set, s2_set = set(s1_list), set(s2_list)\n",
    "        s1_not_in_s2, s2_not_in_s1 = s1_set - s2_set, s2_set - s1_set\n",
    "\n",
    "        s1_elements_to_remove = []\n",
    "        for s in s1_not_in_s2:\n",
    "            if s1_freq[s] > 1:\n",
    "                s1_elements_to_remove.append(s)\n",
    "        for e in s1_elements_to_remove:\n",
    "            s1_not_in_s2.remove(e)\n",
    "\n",
    "        s2_elements_to_remove = []\n",
    "        for s in s2_not_in_s1:\n",
    "            if s2_freq[s] > 1:\n",
    "                s2_elements_to_remove.append(s)\n",
    "        for e in s2_elements_to_remove:\n",
    "            s2_not_in_s1.remove(e)\n",
    "\n",
    "        ans_set = s1_not_in_s2 | s2_not_in_s1\n",
    "        return list(ans_set)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        d = Counter(s1.split()) + Counter(s2.split())\n",
    "        w = []\n",
    "        for i in d:\n",
    "            if d[i] == 1:\n",
    "                w.append(i)\n",
    "        return w"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        c1=Counter(s1.split())\n",
    "        c2=Counter(s2.split())\n",
    "        l=[]\n",
    "        for i in c1:\n",
    "            if c1[i]==1 and c2[i]==0:\n",
    "                l.append(i)\n",
    "        for i in c2:\n",
    "            if c2[i]==1 and c1[i]==0:\n",
    "                l.append(i)\n",
    "        return l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        s1=s1.split(' ')\n",
    "        s2=s2.split(' ')\n",
    "        s1=Counter(s1)\n",
    "        s2=Counter(s2)\n",
    "        result=[]\n",
    "        for s in s1:\n",
    "            if s1[s]==1 and s not in s2:\n",
    "                result.append(s)\n",
    "        for s in s2:\n",
    "            if s2[s]==1 and s not in s1:\n",
    "                result.append(s)\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        freq = {}\n",
    "        for word in s1.split(\" \"):\n",
    "            if word in freq:\n",
    "                freq[word] = 0\n",
    "            else:\n",
    "                freq[word] = 1\n",
    "\n",
    "        for word in s2.split(\" \"):\n",
    "            if word in freq:\n",
    "                freq[word] = 0\n",
    "            else:\n",
    "                freq[word] = 1\n",
    "\n",
    "        return [word for word in freq if freq[word] == 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        \"\"\"\n",
    "        1.Counter()函数为统计词语出现的频数\n",
    "        2.去除空格，将两个字符串相加起来为一个字符串\n",
    "        3.查看只出现一次的单词\n",
    "        \"\"\"\n",
    "        res = Counter(s1.split()) + Counter(s2.split())\n",
    "        \n",
    "        ans = []\n",
    "        for k, v in res.items():\n",
    "            if v == 1:\n",
    "                ans.append(k)\n",
    "\n",
    "        return ans \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        word1 = s1.split(' ')\n",
    "        word2 = s2.split(' ')\n",
    "        word_dict1 = Counter(word1)\n",
    "        word_dict2 = Counter(word2)\n",
    "        ans_dic=[]\n",
    "        for word, ord in word_dict1.items():\n",
    "            if word not in word_dict2 and ord == 1:\n",
    "                ans_dic.append(word)\n",
    "        for word, ord in word_dict2.items():\n",
    "            if word not in word_dict1 and ord == 1:\n",
    "                ans_dic.append(word)\n",
    "        return ans_dic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        return [key for key,value in Counter((s1+\" \"+s2).split(\" \")).items() if value==1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        list1, list2 = s1.split(' '), s2.split(' ')\n",
    "        set1, set2 = {}, {}\n",
    "        for word in list1:\n",
    "            if word in set1:\n",
    "                set1[word] += 1\n",
    "            else:\n",
    "                set1[word] = 1\n",
    "        for word in list2:\n",
    "            if word in set2:\n",
    "                set2[word] += 1\n",
    "            else:\n",
    "                set2[word] = 1\n",
    "        ans = []\n",
    "        for word in set1:\n",
    "            if set1[word] == 1 and word not in set2:\n",
    "                ans.append(word)\n",
    "        for word in set2:\n",
    "            if set2[word] == 1 and word not in set1:\n",
    "                ans.append(word)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        ss1=s1.split()\n",
    "        ss2=s2.split()\n",
    "        sd1=Counter(ss1)\n",
    "        sd2=Counter(ss2)\n",
    "        ans=[]\n",
    "        for key in sd1:\n",
    "            if sd1[key]==1 and key not in sd2:\n",
    "                ans.append(key)\n",
    "        for key in sd2:\n",
    "            if sd2[key]==1 and key not in sd1:\n",
    "                ans.append(key)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        list1 = s1.split(' ')\n",
    "        list2 = s2.split(' ')\n",
    "        list3 = list2 + list1\n",
    "\n",
    "        test1 = Counter(list3)\n",
    "        res = []\n",
    "        for key, value in test1.items():\n",
    "            if value == 1:\n",
    "                res.append(key)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        s1 = s1.split(\" \")\n",
    "        s2 = s2.split(\" \")\n",
    "        dict_s1 = defaultdict(int)\n",
    "        ans = []\n",
    "        for i in s1:\n",
    "            dict_s1[i] += 1\n",
    "        for j in s2:\n",
    "            dict_s1[j] += 1\n",
    "        for key in dict_s1.keys():\n",
    "            if dict_s1[key] == 1:\n",
    "                ans.append(key)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        arr1 = s1.split()\n",
    "        arr2 = s2.split()\n",
    "        cnt1 = Counter(arr1)\n",
    "        cnt2 = Counter(arr2)\n",
    "        res = []\n",
    "        for k, v in cnt1.items():\n",
    "            if v == 1 and k not in cnt2:\n",
    "                res.append(k)\n",
    "        for k, v in cnt2.items():\n",
    "            if v == 1 and k not in cnt1:\n",
    "                res.append(k)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        res = []\n",
    "        s1 = s1.split()\n",
    "        s2 = s2.split()\n",
    "        s = s1+s2\n",
    "        for i in s:\n",
    "            if s.count(i) == 1:\n",
    "                res.append(i)\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\r\n",
    "class Solution:\r\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\r\n",
    "        counter=Counter(s1.split(' '))\r\n",
    "        counter.update(s2.split(' '))\r\n",
    "        ret=[]\r\n",
    "        for k,v in counter.items():\r\n",
    "            if v==1:\r\n",
    "                ret.append(k)\r\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        ans = []\n",
    "        s = s1 + ' ' + s2\n",
    "        count_s = Counter(s.split()).most_common()\n",
    "        for ele, i in count_s:\n",
    "            if i == 1:\n",
    "                ans.append(ele)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\r\n",
    "from collections import Counter\r\n",
    "class Solution:\r\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\r\n",
    "        words1, words2 = s1.split(' '), s2.split(' ')\r\n",
    "        c1, c2 = Counter(words1), Counter(words2)\r\n",
    "        res = []\r\n",
    "        for key in c1:\r\n",
    "            if c1[key] == 1 and key not in c2:\r\n",
    "                res.append(key)\r\n",
    "        for key in c2:\r\n",
    "            if c2[key] == 1 and key not in c1:\r\n",
    "                res.append(key)      \r\n",
    "        return res          "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        c = Counter(s1.split() + s2.split())\n",
    "        return [s for s in c if c[s] == 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        wordlist1,wordlist2 = s1.split(' '),s2.split(' ')\n",
    "        c1,c2 = Counter(wordlist1),Counter(wordlist2)\n",
    "        rec = set()\n",
    "        for word in c1:\n",
    "            if c1[word]>1:\n",
    "                rec.add(word)\n",
    "        for word in c2:\n",
    "            if c2[word]>1:\n",
    "                rec.add(word)\n",
    "        return list((set(wordlist1)^set(wordlist2))-rec)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        res = []\n",
    "        s1 = s1.split()\n",
    "        s2 = s2.split()\n",
    "        s = s1+s2\n",
    "        for i in set(s):\n",
    "            if s.count(i) == 1:\n",
    "                res.append(i)\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        ans = []\n",
    "        cnt1 = Counter(s1.split(\" \"))\n",
    "        cnt2 = Counter(s2.split(\" \"))\n",
    "        for word in list(cnt1.keys()):\n",
    "            if cnt1[word] == 1 and cnt2[word] == 0:\n",
    "                ans.append(word)\n",
    "        \n",
    "        for word in list(cnt2.keys()):\n",
    "            if cnt2[word] == 1 and cnt1[word] == 0:\n",
    "                ans.append(word)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        def wordCount(ss: str) -> defaultdict(int):\n",
    "            words = ss.split()\n",
    "            dmap = defaultdict(int)\n",
    "            for word in words:\n",
    "                dmap[word] += 1\n",
    "            return dmap\n",
    "\n",
    "        #\n",
    "        def wordDiff(dd: defaultdict(int), tt: defaultdict(int), ret: []) -> None:\n",
    "            for word in dd.keys():\n",
    "                if dd[word] == 1 and tt[word] == 0:\n",
    "                    ret.append(word)\n",
    "\n",
    "        d1, d2 = wordCount(s1), wordCount(s2)\n",
    "        ret = []\n",
    "        wordDiff(d1, d2, ret)\n",
    "        wordDiff(d2, d1, ret)\n",
    "        return ret\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> list[str]:\n",
    "        s = s1 + ' ' + s2\n",
    "        res = []\n",
    "        counts = collections.Counter(s.split())\n",
    "        for k, v in counts.items():\n",
    "            if v == 1:\n",
    "                res.append(k)\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        n = []\n",
    "        list1 = s1.split()\n",
    "        list2 = s2.split()\n",
    "        list3 = list1 + list2\n",
    "        count = Counter(list3)\n",
    "        for k, v in count.items():\n",
    "            if v == 1:\n",
    "                n += [k]\n",
    "        return n \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        freq = Counter(s1.split()) + Counter(s2.split())\n",
    "        \n",
    "        ans = list()\n",
    "        for word, occ in freq.items():\n",
    "            if occ == 1:\n",
    "                ans.append(word)\n",
    "        \n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        l1 = s1.split(\" \")\n",
    "        l2 = s2.split(\" \")\n",
    "        res = []\n",
    "        dct = {}\n",
    "        for i in l1:\n",
    "            dct[i] = dct.get(i, 0) +1\n",
    "        for i in l2:\n",
    "            if i not in dct:\n",
    "                dct[i] = dct.get(i, 0) + 1\n",
    "            else:\n",
    "                dct[i] += 1\n",
    "        for i,v in dct.items():\n",
    "            if v == 1:\n",
    "                res.append(i)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    # def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "    #     words1=s1.split(' ')\n",
    "    #     words2=s2.split(' ')\n",
    "    #     dic1=Counter(words1)\n",
    "    #     dic2=Counter(words2)\n",
    "    #     dic=dic2+dic1\n",
    "    #     res=[key for key ,value in dic.items() if value==1]\n",
    "    #     return res\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        words1=s1.split(' ')\n",
    "        words2=s2.split(' ')\n",
    "        dic1=Counter(words1)\n",
    "        dic2=Counter(words2)\n",
    "        res=[]\n",
    "        for key,value in dic1.items():\n",
    "            if value==1:\n",
    "                if key not in dic2:\n",
    "                    res.append(key)\n",
    "        for key,value in dic2.items():\n",
    "            if value==1:\n",
    "                if key not in dic1:\n",
    "                    res.append(key)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        cnt = Counter((s1 + ' ' + s2).split(' '))\n",
    "        return [k for k, v in cnt.items() if v == 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        cnt = Counter(s1.split()) + Counter(s2.split())\n",
    "        return [x for x in cnt if cnt[x] == 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n",
    "        import collections\n",
    "        l1 = s1.split(\" \")\n",
    "        l2 = s2.split(\" \")\n",
    "        sd = collections.Counter(l1+l2)\n",
    "        ans = []\n",
    "        for k , v in sd.items():\n",
    "            if v == 1:\n",
    "                ans.append(k)\n",
    "\n",
    "\n",
    "        return ans"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
